package com.vision.util.http.deal;

import com.vision.util.http.AbsRequestDeal;
import org.apache.http.HttpEntity;
import org.apache.http.client.methods.CloseableHttpResponse;
import org.apache.http.util.EntityUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.io.IOException;

/**
 * @author zhongchao
 * @title
 * @date 2017-08-22
 * @since v1.0.0
 */
public class DetaultRequestDeal extends AbsRequestDeal<String> {

    private static final Logger logger = LoggerFactory.getLogger(DetaultRequestDeal.class);
    private String charset;

    public DetaultRequestDeal(String charset) {
        this.charset = charset;
    }

    @Override
    public void onSuccess(CloseableHttpResponse response) throws IOException {
        HttpEntity entity = response.getEntity();
        logger.info("status:" + response.getStatusLine().getStatusCode());
        responseHeaders = response.getAllHeaders();
        resopnseString = EntityUtils.toString(entity, charset);
    }

    @Override
    public void onException(String url, Exception e) {
        logger.error("request url:{} error:{}", "", e);
    }

    @Override
    public void onFiled() {

    }
}
